package org.xhystudy.rpc.registry.loadbalancer;

import org.xhystudy.rpc.registry.RegistryFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 负载均衡工厂
 * @Author: Xhy
 * @gitee: https://gitee.com/XhyQAQ
 * @copyright: B站: https://space.bilibili.com/152686439
 * @CreateTime: 2023-04-30 21:55
 */
public class LoadBalancerFactory {

    private static Map<LoadBalancerType,ServiceLoadBalancer> serviceLoadBalancerMap = new HashMap<>();

    static {
        serviceLoadBalancerMap.put(LoadBalancerType.CONSISTENT_HASH,new ConsistentHashLoadBalancer());
        serviceLoadBalancerMap.put(LoadBalancerType.RoundRobin,new RoundRobinLoadBalancer());
    }
    public static ServiceLoadBalancer getInstance(LoadBalancerType type) throws Exception {

        return serviceLoadBalancerMap.get(type);
    }
}
